; docformat = 'rst'
;
;  AGAGE_BOX_MODEL_TRANSPORT
;
;+
; :Purpose:
;   Calculate transport matrix based on equations in Cunnold, D. M. et al. (1983). 
;   The Atmospheric Lifetime Experiment 3. Lifetime Methodology and 
;   Application to Three Years of CFCl3 Data. 
;   Journal of Geophysical Research, 88(C13), 8379-8400.
;	
;   This function outputs a 12x12 matrix (F),
;   calculated by collecting terms in the full equation scheme written out below. 
;   Model transport is then calculated as dc/dt=F##c.
;
;   ;Lower troposphere
;   dc[0]+=(c[0]+c[1])/2.*V[0,1] - (c[4]+c[0])/2.*V[4,0]                         - (c[0]-c[1])/T[0,1] + (c[4]-c[0])/T[4,0]
;   dc[1]+=(c[1]+c[2])/2.*V[1,2] - (c[5]+c[1])/2.*V[5,1] - (c[0]+c[1])/2.*V[0,1] - (c[1]-c[2])/T[1,2] + (c[5]-c[1])/T[5,1] + (c[0]-c[1])/T[0,1]
;   dc[2]+=(c[2]+c[3])/2.*V[2,3] - (c[6]+c[2])/2.*V[6,2] - (c[1]+c[2])/2.*V[1,2] - (c[2]-c[3])/T[2,3] + (c[6]-c[2])/T[6,2] + (c[1]-c[2])/T[1,2]
;   dc[3]+=                    -1.*(c[7]+c[3])/2.*V[7,3] - (c[2]+c[3])/2.*V[2,3]                      + (C[7]-c[3])/T[7,3] + (c[2]-c[3])/T[2,3]
;   
;   ;Upper troposphere
;   dc[4]+=5./3.*(c[4]+c[5])/2.*V[4,5] + 5./3.*(c[4]+c[0])/2.*V[4,0]                               - (c[4]-c[5])/T[4,5] - 5./3.*(c[4]-c[0])/T[4,0] + (c[8]-c[4])/T[8,4]
;   dc[5]+=5./3.*(c[5]+c[6])/2.*V[5,6] + 5./3.*(c[5]+c[1])/2.*V[5,1] - 5./3.*(c[4]+c[5])/2.*V[4,5] - (c[5]-c[6])/T[5,6] - 5./3.*(c[5]-c[1])/T[5,1] + (c[9]-c[5])/T[9,5]   + (c[4]-c[5])/T[4,5]
;   dc[6]+=5./3.*(c[6]+c[7])/2.*V[6,7] + 5./3.*(c[6]+c[2])/2.*V[6,2] - 5./3.*(c[5]+c[6])/2.*V[5,6] - (c[6]-c[7])/T[6,7] - 5./3.*(c[6]-c[2])/T[6,2] + (c[10]-c[6])/T[10,6] + (c[5]-c[6])/T[5,6]
;   dc[7]+=                              5./3.*(c[7]+c[3])/2.*V[7,3] - 5./3.*(c[6]+c[7])/2.*V[6,7]                      - 5./3.*(c[7]-c[3])/T[7,3] + (c[11]-c[7])/T[11,7] + (c[6]-c[7])/T[6,7]
;
;   ;Stratosphere
;   dc[8]+= -1.*(c[8]-c[9])/T[8,9]     - 3./2.*(c[8]-c[4])/T[8,4]
;   dc[9]+= -1.*(c[9]-c[10])/T[9,10]   - 3./2.*(c[9]-c[5])/T[9,5]   + (c[8]-c[9])/T[8,9]
;   dc[10]+=-1.*(c[10]-c[11])/T[10,11] - 3./2.*(c[10]-c[6])/T[10,6] + (c[9]-c[10])/T[9,10]
;   dc[11]+=                           - 3./2.*(c[11]-c[7])/T[11,7] + (c[10]-c[11])/T[10,11]
;
; :History:
;   Written by: Matt Rigby, University of Bristol, Mar 23, 2012
;
;-
function agage_box_model_transport, V1_in, intersection_V1, T_in, intersection_T

  compile_opt idl2, hidden

  F=dblarr(12, 12)
  T=dblarr(12, 12)
  V=dblarr(12, 12)

  for n=0, n_elements(intersection_V1[0, *])-1 do begin
	V[intersection_V1[0, n], intersection_V1[1, n]]=1./V1_in[n]
  endfor
  for n=0, n_elements(intersection_T[0, *])-1 do begin
	T[intersection_T[0, n], intersection_T[1, n]]=T_in[n]
  endfor

  F[[0, 1, 4], 0]=[V[0, 1]/2. - V[4, 0]/2. - 1./T[0, 1] - 1./T[4, 0], $
    V[0, 1]/2. + 1./T[0, 1], $
    -1.*V[4, 0]/2. + 1./T[4, 0]]
  
  F[[0, 1, 2, 5], 1]=[-1.*V[0, 1]/2. + 1./T[0, 1], $
    V[1, 2]/2. - V[5, 1]/2. - V[0, 1]/2. - 1./T[1, 2] - 1./T[5, 1] - 1./T[0, 1], $
    V[1, 2]/2. + 1./T[1, 2], $
    -1.*V[5, 1]/2. + 1./T[5, 1]]  
  
  F[[1, 2, 3, 6], 2]=[-1.*V[1, 2]/2. + 1./T[1, 2], $
    V[2, 3]/2. - V[6, 2]/2. - V[1, 2]/2. - 1./T[2, 3] - 1./T[6, 2] - 1./T[1, 2], $
    V[2, 3]/2. + 1./T[2, 3], $
    -1.*V[6, 2]/2. + 1./T[6, 2]]  
  
  F[[2, 3, 7], 3]=[-1.*V[2, 3]/2. + 1./T[2, 3], $
    -1.*V[7, 3]/2. - V[2, 3]/2. - 1./T[7, 3] - 1./T[2, 3], $
    -1.*V[7, 3]/2. + 1./T[7, 3]]
  
  F[[0, 4, 5, 8], 4]=[5./3.*V[4, 0]/2. + 5./3./T[4, 0], $
    5./3.*V[4, 5]/2. + 5./3.*V[4, 0]/2. - 1./T[4, 5] - 5./3./T[4, 0] - 1./T[8, 4], $
    5./3.*V[4, 5]/2. + 1./T[4, 5], $
    1./T[8, 4]]
  
  F[[1, 4, 5, 6, 9], 5]=[5./3.*V[5, 1]/2. + 5./3./T[5, 1], $
    -5./3.*V[4, 5]/2. + 1./T[4, 5], $
    5./3.*V[5, 6]/2. + 5./3.*V[5, 1]/2. - 5./3.*V[4, 5]/2. - 1./T[5, 6] - 5./3./T[5, 1] - 1./T[9, 5] - 1./T[4, 5], $
    5./3.*V[5, 6]/2. + 1./T[5, 6], $
    1./T[9, 5]]
  
  F[[2, 5, 6, 7, 10], 6]=[5./3.*V[6, 2]/2. + 5./3./T[6, 2], $
    -5./3.*V[5, 6]/2. + 1./T[5, 6], $
    5./3.*V[6, 7]/2. + 5./3.*V[6, 2]/2. - 5./3.*V[5, 6]/2. - 1./T[6, 7] - 5./3./T[6, 2] - 1./T[10, 6] - 1./T[5, 6], $
    5./3.*V[6, 7]/2. + 1./T[6, 7], $
    1./T[10, 6]]
  
  F[[3, 6, 7, 11], 7]=[5./3.*V[7, 3]/2. + 5./3./T[7, 3], $
    -5./3.*V[6, 7]/2. + 1./T[6, 7], $
    5./3.*V[7, 3]/2. - 5./3.*V[6, 7]/2. - 5./3./T[7, 3] - 1./T[11, 7] - 1./T[6, 7], $
    1./T[11, 7]]
  
  F[[4, 8, 9], 8]=[3./2./T[8, 4], $
    -1./T[8, 9] - 3./2./T[8, 4], $
    1./T[8, 9]]
  
  F[[5, 8, 9, 10], 9]=[3./2./T[9, 5], $
    1./T[8, 9], $
    -1./T[9, 10] - 3./2./T[9, 5] - 1./T[8, 9], $
    1./T[9, 10]]
  
  F[[6, 9, 10, 11], 10]=[3./2./T[10, 6], $
    1./T[9, 10], $
    -1./T[10, 11] - 3./2./T[10, 6] - 1./T[9, 10], $
    1./T[10, 11]]
  
  F[[7, 10, 11], 11]=[3./2./T[11, 7], $
    1./T[10, 11], $
    -3./2./T[11, 7] -1./T[10, 11]]
  
  return, F

end